package util;


import org.springframework.boot.system.ApplicationHome;
import org.springframework.util.ResourceUtils;

import java.io.File;

//单例模式

//考虑到打包后的部署问题，所有的路径都在这里注册

//使用单例模式；
public  class ResourcePath {

   public static ResourcePath getResInstance() {
      return ResInstance;
   }

   private static final ResourcePath ResInstance=new ResourcePath();

   public final String AvatarResource =getPath("upload/img/avatar");

   public final String classResource =getPath("upload/img/class");

   public final String ProblemResource =getPath("upload/img/problem");

   public final String tempResource =getPath("upload/temp");

   private String getPath(String folder){
      try {
         ApplicationHome application = new ApplicationHome(getClass());
         String rootPath= application.getSource().getParentFile().toString();
         var path =rootPath+File.separator+folder;
         File file = new File(path);
         if (!file.exists() && !file.isDirectory()) {
            file.mkdirs();
         }
         return path;
      }
      catch (Exception e){
         return null;
      }
   }




   private ResourcePath(){}



}
